import { createStore } from 'vuex';
import { defState, StateObject, TabObject } from './defaultState';

export default createStore({
  state: defState,
  getters: {
    currentApp( state: StateObject){
      return state.currentApp
    },
    tabs( state: StateObject){
      return state.tabs
    },
    barContent( state: StateObject ){
      return state.barContent
    }
  },
  mutations: {
    CHANGE_COUNT(state: StateObject, data: number) {
      state.count = data;
    },
    CHANGE_CURRENTAPP(state: StateObject, data: string){
      state.currentApp = data
    },
    APPEND_TAB(state: StateObject, data: TabObject){
      for(let i=0; i<state.tabs.length; i++){
        if(state.tabs[i].apptag === data.apptag){
          return data.apptag
        }
      }
      state.tabs.push( data )
      return data.apptag
    },
    CHANGE_BARCONETENT(state: StateObject, data: []){
      state.barContent = data
    }
  },
  actions: {},
  modules: {}
})